<?php

/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */

/**
 * Description of adm
 *
 * @author dmitry
 */
class Models_Adm extends Access_Db{
    //put your code here
    public function getField($table,$col = 'name')
    {
        
       $result = $this->executeQuery('
                             SELECT ID,' . $col . '
                             FROM ' . $table) ;
       while ($row = mysql_fetch_assoc($result))
       {
           $field[$row['ID']] = $row[$col] ;
       }
       
       return $field ;
    }
    
    

    public function setMenu($visible,$name,$description)
    {
        $this->executeQuery("INSERT INTO yyMenu (ID,visible,name,description)
                             VALUES (NULL,'$visible','$name','$description')") ;
    }
    
    public function setCategory($menuID,$visible,$name,$description)
    {
        $this->executeQuery("INSERT INTO yyCategories (ID,menuID,visible,name,description)
                             VALUES (NULL,'$menuID','$visible','$name','$description')") ;
    }


    public function addCategory($menu)
    {
        
        
        
        echo '<div class="maincomment">
               <form action="/' . $this->path . 'adm/setcategory" method="POST">
                <div class="radio">
                <label>Visible</label><input type="radio" name="visible" value="1">
                <label>UnVisible</label><input type="radio" name="visible" value="0">
                </div>
                <div class="input">
                <select name="menuID">
                <OPTION SELECTED >Select menu</OPTION>' ;
        foreach ($menu as $id => $name)
        {
            echo '<option value="' . $id . '">' . $name . '</option>' ;
        }
        echo   '</select>
                </div>
                
                <div class="input">
                <input type="text" name="categoryname" value="CategoryName" 
                onfocus="if (this.value == this.defaultValue){this.value = \'\';}">
                </div>
                <textarea class="elm1" name="description" rows="15" cols="80">
                </textarea>
                <input type="submit" value="add category">
              </form>
             </div>
            ';
        
        echo '<div class="subcomment">' ;
        if(!isset ($_POST['menu']))
        {
          
          echo '<form action="/' . $this->path . 'adm/addcategory" method="POST">
                   <input type="submit" name="menu" value="setmenu">
                </form>';
        } else {
            echo '<form action="/' . $this->path . 'adm/setmenu" method="POST">
                    <div class="radio">
                    <label>Visible</label><input type="radio" name="visible" value="1" CHECKED>
                    <label>UnVisible</label><input type="radio" name="visible" value="0">
                    </div>
                    <div class="input">
                    <input type="text" name="menuname" value="MenuName" 
                    onfocus="if (this.value == this.defaultValue){this.value = \'\';}">
                    </div>
                    <textarea class="elm1" name="description" rows="15" cols="80">
                    </textarea>
                    <input type="submit" value="add menu">
                  </form>' ;
        }
        echo '</div>' ;
        
    }
    
    public function showAllCategories()
    {
        $category = $this->getField('yyCategories') ;
        foreach ($category as $id => $name)
        {
            echo '<div class="line">
                    <div class="goodid">' . $id . '</div>
                    <div class="goodvalue">' . $name . 
                        '<div class="opt">
                            <a href="/' . $this->path . 'adm/delcategory/' . $id . '">
                                 <img src="/' . $this->path . 'public/imgpage/del.png">
                             </a>
                             <a href="/' . $this->path . 'adm/editcategory/' . $id . '">
                                 <img src="/' . $this->path . 'public/imgpage/pencil.png">
                             </a>
                         </div>
                    </div>
                  </div>' ;
        }
    }
    
    public function delCategory($id)
    {
        $this->executeQuery('DELETE FROM yyCategories
                             WHERE ID=' . $id) ;
        header('Location: /' . $this->path . 'adm/showallcategories') ;
    }

    public function editCategory($id)
    {
        $category = mysql_fetch_assoc($this->executeQuery('SELECT name,description,menuID,visible
                                         FROM yyCategories
                                         WHERE ID=' . $id)) ;
        $menu = $this->getField('yyMenu') ;
        echo '<div class="maincomment">
                <form action="/' . $this->path . 'adm/seteditcategory/' . $id . '" method="POST">
                    <input type="text" name="name" class="input" value="' . $category['name'] . '">
                    <textarea name="content" class="elm1" rows="15" cols="80">
                        ' . $category['description'] . '
                    </textarea>
                    <select name="categoryID">
                        <OPTION SELECTED value="' . $category['menuID'] . '">' . $menu[$category['menuID']] . '</OPTION>' ;
        unset ($menu[$category['menuID']]) ;
        foreach ($menu as $id => $name)
        {
            echo '<option value="' . $id . '">' . $name . '</option>' ;
        }
                    
          echo '    </select>
                    <div class="radio">
                    <label>Visible</label><input type="radio" name="visible" value="1" CHECKED>
                    <label>UnVisible</label><input type="radio" name="visible" value="0">
                     </div>
                     <input type="submit" value="Змінити">
                </form>
                
              </div>';
    }
    
    public function setEditCategory($id,$name,$description,$menuID,$visible)
    {
        $this->executeQuery("UPDATE yyCategories
                             SET name='$name',description='$description',menuID='$menuID',visible='$visible'
                             WHERE ID=$id") ;
        header('Location: /' . $this->path . 'adm/showallcategories') ;
    }

    public function addGoods($category,$property)
    {
        echo '<div class="subcomment">
            <form action="/' . $this->path . 'adm/addgoods" method="POST">
                Характеристики:<input type="text" name="count">
                Картинки:<input type="text" name="countpic">
                <input type="submit" name="setcount" value="set">
              </form>
              </div>' ;
        echo '<div class="maincomment">
               <form action="/' . $this->path . 'adm/setgoods"  method="POST" enctype="multipart/form-data">
                <div class="radio">
                <label>Visible</label><input type="radio" name="visible" value="1">
                <label>UnVisible</label><input type="radio" name="visible" value="0">
                </div>
                <input type="file" name="pic_0"><br>' ;
        if(isset ($_POST['setcount']))
        {
            for($i=1;$i<=($_POST['countpic']-1);$i++)
            {
                echo '<input type="file" name="pic_' . $i . '"><br>' ;
            }
        }
        echo  '<div class="input">
                
                <select name="categoryID">
                <OPTION SELECTED >Select category</OPTION>' ;
        foreach ($category as $id => $name)
        {
            echo '<option value="' . $id . '">' . $name . '</option>' ;
        }
        echo   '</select>
                </div>
                
                <div class="input">
                <input type="text" name="goodsname" value="GoodsName" 
                onfocus="if (this.value == this.defaultValue){this.value = \'\';}">
                <input type="text" name="art" value="art" 
                onfocus="if (this.value == this.defaultValue){this.value = \'\';}">
                <input type="text" name="price" value="price" 
                onfocus="if (this.value == this.defaultValue){this.value = \'\';}">
                </div>' ;
         if (isset ($_POST['setcount']))
         {  
            
             for($i=0;$i<$_POST['count'];$i++)
             {
                echo '<select name="property_' . $i . '">
                <OPTION SELECTED >Select category</OPTION>' ;
                foreach ($property as $id => $name)
                {
                    echo '<option value="' . $id . '">' . $name . '</option>' ;
                }
                echo   '</select>
                        <input type="text" name="' . $i . '"><br>' ;
             }
         }
         if(!isset ($_POST['count']) and !isset ($_POST['countpic']))
         {
             $_POST['count'] = 0 ;
             $_POST['countpic'] = 0 ;
         }
         echo  '<input type="hidden" value="' . $_POST['count'] . '" name="propertycount">
                <input type="hidden" value="' . $_POST['countpic'] . '" name="piccount">
             <input type="submit" value="add goods">
              </form>
             </div>';
    }
    
    
    public function setGoods($insert,$property)
    {
        $this->executeQuery("INSERT INTO yyProducts (ID,visible,categoryID,name,price,added,art)
                             VALUES (NULL,'".$insert['visible']."','".$insert['categoryID']."','".$insert['goodsname']."'
                                 ,'".$insert['price']."',NOW(),'".$insert['art']."')") ;
        $result = mysql_fetch_assoc($this->executeQuery('SELECT last_insert_id()
            FROM yyProducts')) ;
        $count = count($property) ;
        $ex = 0;
        $query = '';
        foreach ($property as $id => $value)
        {
            $query .= "(NULL,'".$result['last_insert_id()']."','$id','$value')" ;
            $ex++ ;
            if($ex != $count)
            {
                $query .= ',' ;
            }
            
        }
        $this->executeQuery('INSERT INTO yyProductProperties (ID,productID,propertyID,value)
                             VALUES ' . $query) ;

        $dir = '/home/vhosts/student.pz.if.ua/www/~yermolayev/sm/public/pic/';
        $ftpDir = '/www/~yermolayev/sm/public/pic/' ;
        $connID = @ftp_connect('localhost', 21, 5); 
        if($connID) 
        {
            $loginResult = @ftp_login($connID, 'student', 'student'); 
            if($loginResult) 
            {
               //=========================================================================================
                ftp_pasv ($connID, TRUE); 
                if(!is_dir($dir . '/' . $insert['categoryID']))
                {
                    ftp_mkdir ($connID, $ftpDir . $insert['categoryID']);
                }
                ftp_mkdir ($connID, $ftpDir . $insert['categoryID']. '/'. $result['last_insert_id()']);
                //=========================================================================================
            }
        }
        
        
        if(isset ($_POST['piccount']))
        {
            for($i=0;$i<$_POST['piccount'];$i++)
            {
                $uploadFile = $ftpDir . $insert['categoryID']. '/'. $result['last_insert_id()'] .'/'. basename($_FILES['pic_'.$i]['name']) ;
               // move_uploaded_file($_FILES['pic_'.$i]['tmp_name'], $uploadFile) ;
                ftp_put($connID, $uploadFile, $_FILES['pic_'.$i]['tmp_name'], FTP_BINARY);
                $image[$_FILES['pic_'.$i]['name']] = $insert['categoryID']. '/'. $result['last_insert_id()'] .'/' ;
            }
        }
        ftp_close($connID);
        $ex = 0;
        $query = '';
        $count = count($image) ;
        foreach ($image as $name => $path)
        {
            if($ex != 0)
            {
                $main = 0 ;
            } else {$main = 1;}
            $query .= "(NULL,'".$result['last_insert_id()']."','$main','$name','$path')" ;
            $ex++ ;
            if($ex != $count)
            {
                $query .= ',' ;
            }
            
        }
        echo $query;
        $this->executeQuery('INSERT INTO yyPictures (ID,productID,main,name,path)
                             VALUES ' . $query) ;
        
        header("Location: /$this->path" . 'products/goods/' . $result['last_insert_id()']) ;
    }
    
    public function showAllGoods()
    {
        $goods = $this->getField('yyProducts') ;
        foreach ($goods as $id => $name)
        {
            echo '<div class="line">
                    <div class="goodid">' . $id . '</div>
                    <div class="goodvalue">' . $name . 
                        '<div class="opt">
                            <a href="/' . $this->path . 'adm/delgoods/' . $id . '">
                                 <img src="/' . $this->path . 'public/imgpage/del.png">
                             </a>
                             <a href="/' . $this->path . 'adm/editgoods/' . $id . '">
                                 <img src="/' . $this->path . 'public/imgpage/pencil.png">
                             </a>
                         </div>
                    </div>
                  </div>' ;
        }
    }

    public function delGoods($id)
    {
        $this->executeQuery('DELETE FROM yyProducts
                             WHERE ID=' . $id) ;
        header('Location: /' . $this->path . 'adm/showallgoods') ;    
    }
    
    public function editGoods($id)
    {
        $goods = mysql_fetch_assoc($this->executeQuery('SELECT art,categoryID,name,price,visible
                                                        FROM yyProducts
                                                        WHERE ID=' . $id)) ;
        $category = $this->getField('yyCategories') ;
        $result = $this->executeQuery('SELECT yyProperties.name,yyProductProperties.value,yyProductProperties.ID
                                       FROM yyProperties,yyProductProperties
                                       WHERE yyProperties.ID=yyProductProperties.propertyID
                                       AND yyProductProperties.productID=' . $id) ;
        echo '<div class="maincomment">
                <form action="" method="POST">
                    Назва:<input type="text" class="input" name="name" value="' . $goods['name'] . '">
                    Арт:<input type="text" class="input" name="name" value="' . $goods['art'] . '">
                    Ціна:<input type="text" class="input" name="name" value="' . $goods['price'] . '">
                    Категорія:<div class="input">
                        <select name="categoryID">
                            <OPTION SELECTED value="' .$goods['categoryID'] . '">' . 
                $category[$goods['categoryID']] . '</OPTION>' ;
        unset($category[$goods['categoryID']]) ;
        foreach ($category as $id => $name)
        {
            echo '<option value="' . $id . '">' . $name . '</option>' ;
        }
        echo   '</select>
                    </div>
                    <div class="radio">
                    <label>Visible</label><input type="radio" name="visible" value="1" CHECKED>
                    <label>UnVisible</label><input type="radio" name="visible" value="0">
                     </div>
                     <input type="submit" value="Змінити">
                </form>
              </div>' ;
        echo '<div class="info">' ;
        while ($row = mysql_fetch_assoc($result))
        {
            echo '<div class="line">
                    <div class="propertyname">' . $row['name'] . '</div>
                    <div class="propertyvalue">' . $row['value'] . '
                        <div class="opt"><a href="/' . $this->path . 'adm/delproductproperty/' . $row['ID'] . '">
                             <img src="/' . $this->path . 'public/imgpage/del.png">
                        </a></div></div>
                  </div>' ;
        }        
        echo '<form action="" method="POST">
                <input type="submit" value="Додати">
              </form>
            </div>' ;
        
    }
    
    public function delProductProperty($id)
    {
        $this->executeQuery('DELETE FROM yyProductProperties
                             WHERE ID=' . $id) ;
        header('Location: ' . $_SERVER['HTTP_REFERER']) ;
    }
    
    public function showAllUsers()
    {
        $users = $this->getField('yyUsers','login') ;
        foreach ($users as $id => $name)
        {
            echo '<div class="line">
                    <div class="goodid">' . $id . '</div>
                    <div class="goodvalue">' . $name . 
                        '<div class="opt">
                            <a href="/' . $this->path . 'adm/delgoods/' . $id . '">
                                 <img src="/' . $this->path . 'public/imgpage/del.png">
                             </a>
                             <a href="/' . $this->path . 'adm/edituser/' . $id . '">
                                 <img src="/' . $this->path . 'public/imgpage/pencil.png">
                             </a>
                         </div>
                    </div>
                  </div>' ;
        }
        
    }
    
    public function editUser($id)
    {
        $user = mysql_fetch_assoc($this->executeQuery('SELECT yyUsers.login,yyUsers.email,yyGroups.name
                                                       FROM yyUsers,yyGroups
                                                       WHERE yyUsers.ID=' . $id .
                                                       ' AND yyUsers.groupID=yyGroups.ID')) ;
        echo '<div class="maincomment">
                <div class="line">
                    <div class="propertyname">' . $user['login'] . '</div>
                    <div class="propertyvalue">' . $user['email'] . '</div>
                </div>
                <form action="/' . $this->path . 'adm/setuser/' . $id . '" method="POST">
                    <div class="input">
                        <select name="groupID">
                            <OPTION SELECTED >' . $user['name'] . '</OPTION>' ;
        $group = $this->getField('yyGroups') ;
        foreach ($group as $id => $name)
        {
            if($user['name'] !== $name)
            echo '<option value="' . $id . '">' . $name . '</option>' ;
        }
        echo   '</select>
                    </div>
                <input type="submit" value="Змінити">
                </form>
              </div>';
        
    }
    
    public function setEditUser($userID,$groupID)
    {
        $this->executeQuery('UPDATE yyUsers
                             SET groupID=' . $groupID .
                             ' WHERE ID=' . $userID) ;
        header('Location: /' . $this->path . 'adm/showallusers') ;
    }


    public function showAllProperties()
    {
        $property = $this->getField('yyProperties') ;
        echo '<div class="subcomment">
                <form action="/' . $this->path . 'adm/setproperty" method="POST">
                    <input type="text" name="name">
                    <input type="submit" value="Додати">
                </form>
              </div>' ;
        foreach ($property as $id => $name)
        {
            echo '<div class="line">
                    <div class="goodid">' . $id . '</div>
                    <div class="goodvalue">' . $name . 
                        '<div class="opt">
                            <a href="/' . $this->path . 'adm/delproperty/' . $id . '">
                                 <img src="/' . $this->path . 'public/imgpage/del.png">
                             </a>
                             <a href="/' . $this->path . 'adm/edituser/' . $id . '">
                                 <img src="/' . $this->path . 'public/imgpage/pencil.png">
                             </a>
                         </div>
                    </div>
                  </div>' ;
        }
        
    }
    
    public function setProperty($name)
    {
        $this->executeQuery("INSERT INTO yyProperties
                             (name)
                             VALUES ('$name')") ;
        header('Location: /' . $this->path . 'adm/showproperties') ;
    }
    
    public function delProperty($id)
    {
        $this->executeQuery("DELETE FROM yyProperties
                             WHERE ID=$id") ;
        header('Location: /' . $this->path . 'adm/showproperties') ;
    }
    
    public function showAllOrders()
    {
        $result = $this->executeQuery('
                             SELECT ID,userID
                             FROM yyUserOrder
                             WHERE status=0' ) ;
           while ($row = mysql_fetch_assoc($result))
           {
               $field[$row['ID']] = $row['userID'] ;
           }
        
        $order = $field ;
        $i = 0 ;
        foreach ($order as $id => $userID)
        {
            $info  = $this->executeQuery('SELECT yyUserOrder.sum,yyUserOrder.added,
                                            yyUsers.login
                                            FROM yyUserOrder,yyUsers
                                            WHERE yyUsers.ID=yyUserOrder.userID
                                            AND yyUserOrder.status=0
                                            AND yyUserOrder.userID=' . $userID. ' 
                                                LIMIT ' . $i . ',1') ;
            $user = mysql_fetch_assoc($info) ;
            
                
            
            echo '<div class="maincomment">' .
                    $user['login'] . '-' . $user['added'] . '-' . $user['sum'] .
                  '<div class="opt">
                             <a href="/' . $this->path . 'adm/showorder/' . $id . '">
                                 <img src="/' . $this->path . 'public/imgpage/pencil.png">
                             </a>
                             <a href="/' . $this->path . 'adm/status/' . $id . '">
                                 <img src="/' . $this->path . 'public/imgpage/check.png">
                             </a>
                         </div>
                     </div>' ;
            $i++ ;
            
        }
    }
    
    public function status($id)
    {
        $this->executeQuery("UPDATE yyUserOrder
                             SET status='1'
                             WHERE ID=$id") ;
        header('Location: /' . $this->path . 'adm/showorders') ;
    }


    public function showOrder($id)
    {
        $result = $this->executeQuery('SELECT yyProducts.name,yyProducts.price,yyProducts.ID
                                           FROM yyProducts,yyOrders
                                           WHERE yyProducts.ID=yyOrders.productID
                                           AND yyOrders.userOrderID=' . $id) ;
            echo '<div class="subcomment">' ;
            while($row = mysql_fetch_assoc($result))
            {
                echo '<div class="line">
                        <div class="goodvalue">
                            <a href="/' . $this->path . 'products/goods/' . $row['ID'] . '">
                                ' . $row['name'] . '
                            </a>
                        </div>
                        <div class="goodid">' . $row['price'] . '</div>
                      </div>' ;
            }
            echo '</div>';

    }
    
    public function editComment($id)
    {
        $row = mysql_fetch_assoc($this->executeQuery('SELECT yyProductDiscussion.ID,yyProductDiscussion.content,
            yyProductDiscussion.added,yyUsers.login,yyProductDiscussion.productID,yyProducts.name
            FROM yyProductDiscussion,yyUsers,yyProducts
            WHERE yyProductDiscussion.productID=yyProducts.ID
            AND yyProductDiscussion.userID=yyUsers.ID
            AND yyProductDiscussion.ID=' . $id)) ;
        echo '<div class="maincomment">
                    Коментар до:[' . $row['productID'] . ']
                    <a href="/' . $this->path . 'products/goods/' . $row['productID'] . '">[' . $row['name'] . ']
                    </a>
                <div class="headcomment">
                    <div class="username"> [' . $row['login'] . ']</div>
                    <div class="date"> added : [' . $row['added'] . ']</div>
                </div>
                <div class="commentcontent">
                    <form action="/' . $this->path . 'adm/setcomment/' . $row['ID'] . '" method="POST">
                        <textarea name="content" class="elm1" rows="15" cols="80">' .
                            $row['content']
                        . '</textarea>
                        <input type="hidden" name="product" value="' . $row['productID'] . '">
                        <input type="submit" value="Змінити">
                    </form>
                    <form action="/' . $this->path . 'adm/delcomment/' . $row['ID'] . '" method="POST">
                            <input type="hidden" name="product" value="' . $row['productID'] . '">
                            <input type="submit" value="Видалити">
                    </form>
                </div>
              </div>' ;
    }
    
    public function setComment($id,$content,$product)
    {
        $this->executeQuery("UPDATE yyProductDiscussion
                             SET content='$content'
                             WHERE ID=$id") ;
        header('Location: /' . $this->path . 'products/goods/' . $product) ;
        
    }
    
    public function delComment($id,$product)
    {
        $this->executeQuery("DELETE
                             FROM yyProductDiscussion
                             WHERE ID=$id") ;
        header('Location: /' . $this->path . 'products/goods/' . $product) ;
    }

    public function action($param,$insert=NULL,$property=NULL,$menuID=NULL, $visible=NULL, $name=NULL, $description=NULL)
    {
        /*if ($param == 'addCategory')
        {
            $this->addCategory($this->getField('yyMenu')) ;
        } elseif($param == 'setMenu') {
            $this->setMenu($visible, $name, $description) ;
            $this->addCategory($this->getField('yyMenu')) ;
        } elseif($param == 'setCategory') {
            $this->setCategory($menuID, $visible, $name, $description) ;
            $this->addCategory($this->getField('yyMenu')) ;
        } elseif($param == 'addGoods') {
            $this->addGoods($this->getField('yyCategories'),$this->getField('yyProperties')) ;
        } elseif($param == 'setGoods') {
            $this->setGoods($insert,$property) ;
        } elseif($param == 'allgoods') {
            $this->showAllGoods() ;
        } elseif($param == 'delgoods') {
            $this->delGoods($insert) ;
        } elseif($param == 'allcategories') {
            $this->showAllCategories() ;
        }*/
        
        switch ($param) {
            case 'addCategory':
                $this->addCategory($this->getField('yyMenu')) ;
                break ;
            case 'setMenu':
                $this->setMenu($visible, $name, $description) ;
                $this->addCategory($this->getField('yyMenu')) ;
                break ;
            case 'setCategory':
                $this->setCategory($menuID, $visible, $name, $description) ;
                $this->addCategory($this->getField('yyMenu')) ;
                break ;
            case 'addGoods':
                $this->addGoods($this->getField('yyCategories'),$this->getField('yyProperties')) ;
                break ;
            case 'setGoods':
                $this->setGoods($insert,$property) ;
                break ;
            case 'allgoods':
                $this->showAllGoods() ;
                break ;
            case 'delgoods':
                $this->delGoods($insert) ;
                break ;
            case 'allcategories':
                $this->showAllCategories() ;
                break ;
            case 'delcategory':
                $this->delCategory($insert) ;
                break ;
            case 'allusers':
                $this->showAllUsers() ;
                break ;
            case 'edituser':
                $this->editUser($insert) ;
                break ;
            case 'setuser':
                $this->setEditUser($insert, $property) ;
                break ;
            case 'showallproperties':
                $this->showAllProperties();
                break ;
            case 'setproperty':
                $this->setProperty($insert) ;
                break ;
            case 'delproperty':
                $this->delProperty($insert) ;
                break ;
            case 'showorders':
                $this->showAllOrders();
                break ;
            case 'showorder':
                $this->showOrder($insert) ;
                break ;
            case 'editcomment':
                $this->editComment($insert) ;
                break ;
            case 'setcomment':
                $this->setComment($insert, $property, $name) ;
                break ;
            case 'delcomment':
                $this->delComment($insert, $name) ;
                break ;
            case 'status':
                $this->status($insert) ;
                break ;
            case 'editcategory':
                $this->editCategory($insert) ;
                break ;
            case 'seteditcategory':
                $this->setEditCategory($insert, $name, $description, $menuID, $visible) ;
                break ;
            case 'editgoods':
                $this->editGoods($insert) ;
                break ;
            case 'delproductproperty':
                $this->delProductProperty($insert) ;
                break ;
        }
            
    }
    
    
    
    
    
    public function isAdmin($id,$hash)
    {
        $result = mysql_fetch_assoc($this->executeQuery('SELECT yyUsers.ID,yyUsers.hash
                                       FROM yyUsers,yyGroups
                                       WHERE yyGroups.privilege=\'max\'
                                       AND yyUsers.groupID=yyGroups.ID
                                       AND yyUsers.ID=' . $id)) ;
        if ($result['hash'] == $hash)
        {
            if(session_id() == "")
            {
                session_start() ;
            }
            
            $_SESSION['admHash'] = $hash ;
            return TRUE ;
        }
        return FALSE ;
    }
    
}

?>
